//
//  TVAdditionalCommodity.swift
//  StarTimesON
//
//  Created by Toj on 12/8/22.
//  Copyright © 2022 StarTimes. All rights reserved.
//

import UIKit

struct TVAdditionalCommodity: HandyJSON, DataDeserializer {
    var additionalCommodityId = ""
    var commodityId = ""
    var validTimeEnName = ""
    var validTimeNum = ""
    var currencySymbol = ""
    var currency = ""
    var price: Double = 0
    var listPrice: Double = 0
    var productName = ""
}

class TVAdditionalCommodityCellModel: NSObject {
    var isSelected = false
    
    private(set) var id = ""
    private(set) var commodityId = ""
    
    private(set) var name = ""
    private(set) var productName = ""
    
    // 现价(折扣价)
    private(set) var price: Double = 0
    // 现价(折扣价): 带货币符号
    private(set) var priceString: NSAttributedString?
    // 原价(吊牌价)
    private(set) var listPrice: Double = 0
    // 原价(吊牌价): 带货币符号
    private(set) var listPriceString: NSAttributedString?
    
    // 货币编码, e.g.: "NGN"
    private(set) var currencyCode = ""
    // 货币符号, e.g.: "₦"
    private(set) var currencySymbol = ""

    init(commodity: TVAdditionalCommodity) {
        id = commodity.additionalCommodityId
        commodityId = commodity.commodityId

        name = commodity.validTimeNum + commodity.validTimeEnName
        productName = commodity.productName
        // 货币
        price = commodity.price
        listPrice = commodity.listPrice
        currencyCode = commodity.currency
        currencySymbol = commodity.currencySymbol

        // 折扣价
        let paragraphStyle = NSMutableParagraphStyle()
        paragraphStyle.lineBreakMode = .byTruncatingTail
        paragraphStyle.alignment = .center
        let fontColor = "#554422".to_color
        var attributed = currencySymbol.to_attributedString(font: UIFont.boldSystemFont(ofSize: 10), color: fontColor, paragraph: paragraphStyle)
        let priceAttributed_ = price.st_moneyFormat.st_cleanZero.to_attributedString(font: UIFont.boldSystemFont(ofSize: 18), color: fontColor, paragraph: paragraphStyle)
        attributed.append(priceAttributed_)
        priceString = attributed

        // 原价
        let invalidMoney = currencySymbol + listPrice.st_moneyFormat.st_cleanZero
        attributed = invalidMoney.to_attributedString(font: 12.ui_systemFont, color: "#AAAAAA".to_color, paragraph: paragraphStyle, lineStyle: .strikethrough)
        listPriceString = attributed
    }
}
